package com.example.springback.common;
import java.time.LocalDate;
import java.time.Period;

public class RetireAgeCalculator {
    //男职工退休
    public static LocalDate manRetireAgeCount(LocalDate birthDate){
        //男性职工原退休年龄是60岁
        LocalDate originRetireDate=birthDate.plusYears(60);
        LocalDate retireDate=originRetireDate;
        int retireYear= originRetireDate.getYear();//获取原退休年，2025年之前的不用算
        if(retireYear>=2025) {//2025年之后退休的
            int delayMonth=RetireAgeCalculator.delayMonths(birthDate,"男");
            retireDate=originRetireDate.plusMonths(delayMonth);
        }
        //2025年之前退休的不需要改
        return retireDate;
    }
    //女职工退休
    public static LocalDate womanRetireAgeCount(LocalDate birthDate){
        //女性职工原退休年龄是50岁
        LocalDate originRetireDate=birthDate.plusYears(50);
        LocalDate retireDate=originRetireDate;
        int retireYear= originRetireDate.getYear();//获取原退休年，2025年之前的不用算
        if(retireYear>=2025) {//2025年之后退休的
            int delayMonth=RetireAgeCalculator.delayMonths(birthDate,"女");
            retireDate=originRetireDate.plusMonths(delayMonth);
        }
        //2025年之前退休的不需要改
        return retireDate;
    }
    public static int delayMonths(LocalDate birthDay,String sex){//计算延迟退休多少月
        LocalDate startDate=LocalDate.of(2024,12,31);
        //男性
        int sexNum=4;
        int maxMonth=36;
        int workTime=60;//男性员工原60岁退休
        if(sex=="女"){//女性
            sexNum=2;
            maxMonth=60;
            workTime=50;
        }
        //获取原退休日期与2024年12月的差值
        Period period=Period.between(startDate,birthDay.plusYears(workTime));
        int monthDiff=period.getYears()*12+period.getMonths();
        //根据性别计算
        int delayMonth=monthDiff/sexNum<maxMonth?monthDiff/sexNum:maxMonth;
        if(monthDiff%sexNum>0&&delayMonth<maxMonth){
            delayMonth++;
        }
        return delayMonth;
    }
}
